package main.java.message;

import java.net.ServerSocket;
import java.net.Socket;

import main.java.regression.Regression;

public class MessageListener implements Runnable {
	private int port;
	private ServerSocket listener;
	private Regression regression;

	public MessageListener(int port, Regression regression) {
		setPort(port);
		setRegression(regression);
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public Regression getRegression() {
		return regression;
	}

	public void setRegression(Regression regression) {
		this.regression = regression;
	}

	@Override
	public void run() {
		try {
			listener = new ServerSocket(port);
			while (true) {
				Socket socket = listener.accept();
				(new Thread(new IncomingMessageHandler(socket, getRegression())))
						.start();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

}
